package hn.cch.microservice.service_consumer_fallback_factory.feign.client.fallback.factory;

import feign.hystrix.FallbackFactory;
import hn.cch.microservice.service_consumer_fallback_factory.entity.User;
import hn.cch.microservice.service_consumer_fallback_factory.feign.client.UserFeignClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;

import java.math.BigDecimal;

@Component
public class UserFeignClientFallbackFactory implements FallbackFactory<UserFeignClient> {

    private static final Logger logger = LoggerFactory.getLogger(UserFeignClientFallbackFactory.class);

    @Override
    public UserFeignClient create(Throwable throwable) {
        return new UserFeignClient() {
            @Override
            public User user(@PathVariable(value = "id") Long id) {
                logger.info("throwable:" + throwable);
                User user = new User();
                user.setId(0L);
                user.setAccount("account0");
                user.setName("name0");
                user.setAge(0);
                user.setBalance(BigDecimal.valueOf(0));
                return user;
            }
        };
    }
}
